package mips.instructions;

/**
 * <code>SYSCALL</code> instruction<br/>
 * System Call</br>
 * @author jnmartin84@gmail.com
 */
public class SYSCALL extends Instruction {

	private static final String INSTRUCTION_NAME = "SYSCALL";
	private static SYSCALL INSTANCE = new SYSCALL();

	private SYSCALL(){}

	public static final SYSCALL getInstance() {
		return INSTANCE;
	}

	/**
	 * <b>Format:</b><br/>
	 * SYSCALL<br/><br/>
	 * <b>Description:</b><br/>
	 * A system call exception occurs, immediately and unconditionally<br/>
	 * transferring control to the exception handler.<br/><br/>
	 * The code field is available for use as software parameters, but is retrieved<br/>
	 * by the exception handler only by loading the contents of the memory word<br/>
	 * containing the instruction.<br/><br/>
	 * <b>Operation:</b><br/>
	 * T: SystemCallException<br/>
	 * @throws mips.exceptions.SystemCallException
	 */
	@Override
	public final void execute(final int instruction) throws mips.exceptions.SystemCallException {
		throw new mips.exceptions.SystemCallException(mips.R4300i.PC,instruction); 
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public final String emit(final int instruction) {
		return	"		throw new mips.exceptions.SystemCallException(mips.CPU.PC,"+String.format("0x%08X",instruction)+");\n";
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public final String getName(final int instruction) {
		return getName();
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public final String getName() {
		return INSTRUCTION_NAME;
	}
}